package io.renren.minimito.service.impl;

import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.minimito.dao.SqTagDao;
import io.renren.minimito.entity.SqTagEntity;
import io.renren.minimito.service.SqTagService;
import org.springframework.util.StringUtils;


@Service("sqTagService")
public class SqTagServiceImpl extends ServiceImpl<SqTagDao, SqTagEntity> implements SqTagService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SqTagEntity> page = this.page(
                new Query<SqTagEntity>().getPage(params),
                new QueryWrapper<SqTagEntity>()
        );

        return new PageUtils(page);
    }

    //模糊查询
    @Override
    public PageUtils queryPageByCondition(Map<String, Object> params) {
        QueryWrapper<SqTagEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.and((w)->{
                w.eq("id",key).or().like("tag_name",key).or();
            });
        }
        IPage<SqTagEntity> page = this.page(
                new Query<SqTagEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}